define(function(require, exports, module) {

	var $ = require('jquery');
	require('jquery/jquery-file-upload/8.8.5/vendor/jquery.ui.widget.js');
	require('jquery/jquery-file-upload/8.8.5/jquery.iframe-transport.js');
	require('jquery/jquery-file-upload/8.8.5/jquery.fileupload.js');

	// param
	exports.options = {
		addLink : $CONFIG.base_url + "/api/profile/avatar/update"
	};

	$('#fileupload').fileupload(
			{
				url : $CONFIG.base_url + "/commons/attachment/upload",
				dataType : 'json',
				formData : {
					uid : $g_user.id
				},
				acceptFileTypes : /(\.|\/)(gif|png)$/i,
				maxNumberOfFiles : 1,
				maxFileSize : 5000000,
				done : function(e, data) {

					$.each(data.result, function(index, file) {
						var html = '<img src="' + $CONFIG.base_url
								+ '/commons/attachment/download/' + file.id
								+ '/250x250"/>';
						$('#file-preview').empty().append(html);
						$('#avatar').val(file.id);
					});
				}
			});

	$(".add-submit").click(function() {
		var $form = $("#avatar-form");
		var posting = $.post(exports.options.addLink, $form.serialize());

		/* Put the results in a div */
		posting.done(function(data) {
			alert("保存成功");
		});
	});
});